package service.impl;

import dao.UserMapper;
import entity.User;
import entity.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import service.UserService;

import java.util.List;

//@Service("userService")
@Transactional(propagation=Propagation.REQUIRED,rollbackFor={Exception.class})
public class UserServiceImpl implements UserService {

//	@Autowired
	private UserMapper userDao;
	
	public UserMapper getUserDao() {
		return userDao;
	}

	public void setUserDao(UserMapper userDao) {
		this.userDao = userDao;
	}

	public void add(User user) {
		userDao.insert(user);
//		int i=1/0;
	}

	@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
	public List<User> findAll() {
		return userDao.selectByExample(new UserExample());
	}

	@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
	public User findById(Integer id) {
		return userDao.selectByPrimaryKey(id);
	}

	public void modify(User user) {
		userDao.updateByPrimaryKey(user);
	}

	public void removeById(Integer id) {
		userDao.deleteByPrimaryKey(id);
	}

}
